<template>
	<view class="page">
		<button class="btn1" size="mini" @click="insert">新增</button>
		<uni-list v-for="one in list">
			<uni-card :is-shadow="false">
				<checkbox-group class="check" @change="onchange(one.name, one.phone, one.address)">
					<label><checkbox value="cb" /></label>
				</checkbox-group>
				<view class="name">{{ one.name }}</view>
				<view class="phone">{{ one.phone }}</view>
				<image class="image" src="../../static/dizhi.jpg"></image>
				<view class="address">{{ one.address }}</view>
				<button class="btn2" size="mini" @click="edit(one.name, one.phone, one.address, one.id)">编辑</button>
				<button class="btn3" size="mini" @click="deleteInfo(one.id)">删除</button>
			</uni-card>
		</uni-list>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: []
		};
	},
	onShow() {
		let that = this;
		that.ajax(that.url.searchUserAddressInfo, 'GET', null, function(resp) {
			that.list = resp.data.result;
		});
	},
	methods: {
		onchange(name, phone, address){
			uni.navigateTo({
				url:'/pages/exchange/exchange?name=' + name + '&phone=' + phone + '&address=' + address 
			})
		},
		insert() {
			uni.navigateTo({
				url: '/pages/inset_addressInfo/inset_addressInfo'
			});
		},
		deleteInfo(id) {
			let that = this;
			let data = {
				id: id
			};
			uni.showModal({
				title: '提示信息',
				content: '是否要确认删除？',
				success: function(resp) {
					if (resp.confirm) {
						that.ajax(that.url.deleteAddressInfo, 'POST', data, function(resp) {
							uni.showToast({
								icon: 'none',
								title: '删除成功！'
							});
							setTimeout(function(resp) {
								uni.reLaunch({
									url: '/pages/choose_address/choose_address'
								});
							}, 800);
						});
					}
				}
			});
		},
		edit(name, phone, address, id){
			uni.navigateTo({
				url:'/pages/edit_addressInfo/edit_addressInfo?name=' + name + '&phone=' + phone + '&address=' + address + '&id=' + id
			})
		}
	}
};
</script>

<style lang="less">
@import url('choose_address.less');
</style>
